package com.pkx.guide.info.service.impl;

import com.pkx.guide.info.entity.TInfoNetworkConfig;
import com.pkx.guide.info.mapper.TInfoNetworkConfigMapper;
import com.pkx.guide.info.service.TInfoNetworkConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * 网络配置信息表 服务实现类
 *
 * @author sunsy
 * @since 2024-11-11
 */
@Service
public class TInfoNetworkConfigServiceImpl extends ServiceImpl<TInfoNetworkConfigMapper, TInfoNetworkConfig> implements TInfoNetworkConfigService {

    /**
     * 分页列表
     *
     * @param tInfoNetworkConfig
     * @return
     */
    @Override
    public IPage<TInfoNetworkConfig> pageList(Page page, TInfoNetworkConfig tInfoNetworkConfig) {
        LambdaQueryWrapper<TInfoNetworkConfig> lambdaQueryWrapper = new QueryWrapper<TInfoNetworkConfig>().lambda();
        lambdaQueryWrapper.eq(tInfoNetworkConfig.getGuideType() != null, TInfoNetworkConfig::getGuideType, tInfoNetworkConfig.getGuideType());
        lambdaQueryWrapper.eq(TInfoNetworkConfig::getDelFlg, 0);
        return page(page, lambdaQueryWrapper);
    }

    /**
     * 列表查询
     *
     * @param tInfoNetworkConfig
     * @return
     */
    @Override
    public List<TInfoNetworkConfig> listByEntity(TInfoNetworkConfig tInfoNetworkConfig) {
        LambdaQueryWrapper<TInfoNetworkConfig> lambdaQueryWrapper = new QueryWrapper<TInfoNetworkConfig>().lambda();
        lambdaQueryWrapper.eq(tInfoNetworkConfig.getGuideType() != null, TInfoNetworkConfig::getGuideType, tInfoNetworkConfig.getGuideType());
        lambdaQueryWrapper.eq(TInfoNetworkConfig::getDelFlg, 0);
        return list(lambdaQueryWrapper);
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Override
    public TInfoNetworkConfig selectById(Integer id) {
        return getById(id);
    }

    /**
     * 详情
     *
     * @param guideType
     * @return
     */
    @Override
    public TInfoNetworkConfig selectByGuideType(Integer guideType){
        if (guideType == null){
            return null;
        }
        LambdaQueryWrapper<TInfoNetworkConfig> lambdaQueryWrapper = new QueryWrapper<TInfoNetworkConfig>().lambda();
        lambdaQueryWrapper.eq(TInfoNetworkConfig::getGuideType, guideType);
        lambdaQueryWrapper.eq(TInfoNetworkConfig::getDelFlg, 0);
        lambdaQueryWrapper.last("limit 1");
        return getOne(lambdaQueryWrapper);
    }

    /**
     * 保存
     *
     * @param tInfoNetworkConfig
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveTInfoNetworkConfig(TInfoNetworkConfig tInfoNetworkConfig) {
        return save(tInfoNetworkConfig);
    }

    /**
     * 修改
     *
     * @param tInfoNetworkConfig
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean modify(TInfoNetworkConfig tInfoNetworkConfig) {
        return updateById(tInfoNetworkConfig);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteById(Integer id) {
        if (id == null){
            return false;
        }
        LambdaUpdateWrapper<TInfoNetworkConfig> lambdaUpdateWrapper = new UpdateWrapper<TInfoNetworkConfig>().lambda()
            .eq(TInfoNetworkConfig::getId, id)
            .set(TInfoNetworkConfig::getDelFlg, 1);
        return update(lambdaUpdateWrapper);
    }
}
